package com.api.oa.services.impl;

import cn.hutool.core.util.StrUtil;
import com.api.oa.mapper.YQDistrictMapper;
import com.api.oa.model.entity.YQDistrict;
import com.api.oa.model.vo.OaOrgTreeVO;
import com.api.oa.services.YQDistrictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import java.util.List;


@Service
public class YQDistrictServiceImpl implements YQDistrictService {

    @Autowired
    private YQDistrictMapper mapper;


    @Override
    public Integer add(YQDistrict entity) {
        if (!StrUtil.isEmptyIfStr(entity.getDistrictPid())) {
            YQDistrict one = mapper.findOne(entity.getDistrictPid());
            String r = one.getDistrictRouter() + "/" + one.getDistrictId();
            entity.setDistrictRouter(r);
        }
        return mapper.insert(entity);
    }

    @Override
    public void remove(Integer id) {
        mapper.delete(id);
    }

    @Override
    public Integer update(YQDistrict entity) {
        return mapper.update(entity);
    }

    @Override
    public PageInfo<YQDistrict> list(Integer pid, Integer pageIndex, Integer pageSize) {
        PageHelper.startPage(pageIndex, pageSize);
        PageHelper.orderBy("districtId desc");
        return new PageInfo<>(mapper.list(pid));
    }

    @Override
    public List<YQDistrict> list(Integer pid) {
        return mapper.list(pid);
    }

    @Override
    public YQDistrict one(Integer id) {
        return mapper.findOne(id);
    }


}
